//
//  DHGoodTypeCell.m
//  宏达APP
//
//  Created by DIANGHONG on 2018/5/5.
//  Copyright © 2018年 123. All rights reserved.
//

#import "DHGoodTypeCell.h"
#define ButtonFontSize 14
@interface DHGoodTypeCell()
@property (strong, nonatomic)  UIButton *giftButton; // 赠品
@property (strong, nonatomic)  UIButton *rapBuyButton; // 抢购
@property (strong, nonatomic)  UIButton *xianshiButton; // 限时折扣
@property (strong, nonatomic)  UIButton *virtualButton; // 虚拟
@end

@implementation DHGoodTypeCell

- (UIButton *)giftButton{
    if (!_giftButton) {
        _giftButton = [[UIButton alloc] init];
      //  [_giftButton setBackgroundColor:UIColor.blueColor];
        [_giftButton setTitle:@"赠品" forState:UIControlStateNormal];
        [_giftButton setTitleColor:UIColor.lightGrayColor forState:UIControlStateNormal];
        [_giftButton setTitleColor:UIColor.whiteColor forState:UIControlStateSelected];
        _giftButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontSize];
        [_giftButton setBackgroundImage:[UIImage imageNamed:@"buttonBgImageNor"] forState:UIControlStateNormal];
        [_giftButton setBackgroundImage:[UIImage imageNamed:@"buttonBgImageSelected"] forState:UIControlStateSelected];
        [_giftButton addTarget:self action:@selector(ButtonCilck:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _giftButton;
}
- (UIButton *)rapBuyButton{
    if (!_rapBuyButton) {
        _rapBuyButton = [[UIButton alloc] init];
        [_rapBuyButton setTitle:@"抢购" forState:UIControlStateNormal];
        [_rapBuyButton setTitleColor:UIColor.lightGrayColor forState:UIControlStateNormal];
        [_rapBuyButton setTitleColor:UIColor.whiteColor forState:UIControlStateSelected];
        _rapBuyButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontSize];
        [_rapBuyButton setBackgroundImage:[UIImage imageNamed:@"buttonBgImageNor"] forState:UIControlStateNormal];
        [_rapBuyButton setBackgroundImage:[UIImage imageNamed:@"buttonBgImageSelected"] forState:UIControlStateSelected];
        [_rapBuyButton addTarget:self action:@selector(ButtonCilck:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _rapBuyButton;
}
- (UIButton *)xianshiButton{
    if (!_xianshiButton) {
        _xianshiButton = [[UIButton alloc] init];
        [_xianshiButton setTitle:@"限时折扣" forState:UIControlStateNormal];
        [_xianshiButton setTitleColor:UIColor.lightGrayColor forState:UIControlStateNormal];
        [_xianshiButton setTitleColor:UIColor.whiteColor forState:UIControlStateSelected];
        _xianshiButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontSize];
        [_xianshiButton setBackgroundImage:[UIImage imageNamed:@"buttonBgImageNor"] forState:UIControlStateNormal];
        [_xianshiButton setBackgroundImage:[UIImage imageNamed:@"buttonBgImageSelected"] forState:UIControlStateSelected];
        [_xianshiButton addTarget:self action:@selector(ButtonCilck:) forControlEvents:UIControlEventTouchUpInside];


    }
    return _xianshiButton;
}
- (UIButton *)virtualButton{
    if (!_virtualButton) {
        _virtualButton = [[UIButton alloc] init];
        [_virtualButton setTitle:@"虚拟" forState:UIControlStateNormal];
        [_virtualButton setTitleColor:UIColor.lightGrayColor forState:UIControlStateNormal];
        [_virtualButton setTitleColor:UIColor.whiteColor forState:UIControlStateSelected];
        _virtualButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontSize];
        [_virtualButton setBackgroundImage:[UIImage imageNamed:@"buttonBgImageNor"] forState:UIControlStateNormal];
        [_virtualButton setBackgroundImage:[UIImage imageNamed:@"buttonBgImageSelected"] forState:UIControlStateSelected];
        [_virtualButton addTarget:self action:@selector(ButtonCilck:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _virtualButton;
}


- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.contentView addSubview:self.giftButton];
    [self.contentView addSubview:self.rapBuyButton];
    [self.contentView addSubview:self.xianshiButton];
    [self.contentView addSubview:self.virtualButton];
    
    [self setAutoLayout];

}

- (void)ButtonCilck:(UIButton *)sender{
    sender.selected = !sender.selected;
}
- (void)setAutoLayout{
    CGFloat btnW = (self.bounds.size.width - 5 * 8) / 5;
    CGFloat btnH = self.bounds.size.height - 2 * 8;
    self.giftButton.frame = CGRectMake(8, 5, btnW, btnH);
    self.rapBuyButton.frame = CGRectMake(CGRectGetMaxX(self.giftButton.frame) + 8, 5, btnW, btnH);
    self.xianshiButton.frame = CGRectMake(CGRectGetMaxX(self.rapBuyButton.frame) + 8, 5, btnW + btnW, btnH);
    self.virtualButton.frame = CGRectMake(CGRectGetMaxX(self.xianshiButton.frame) + 8, 5, btnW, btnH);

    
}

@end
